All Questions
565 questions
7votes
5answers
815views
6votes
2answers
187views
Markov sentence generator on input file
This is a Markov chain generator. It reads a file, reads all triples of words, and creates the Markov model. The model it makes is weighted, by which I mean that if "word1 word2 word3" ...
9votes
1answer
618views
Arena/Region allocator in C++
Update: 2nd revision on separate post: Arena/Region Allocator in C++ (rev 2) Original Post Trying to get a better grasp on low-level memory management, I implemented an arena allocator in C++. It's a ...
7votes
3answers
586views
Initialize std::map
I would like to make the initialization code for the C++ std::map instance (table in the example below) a little more clean. ...
7votes
3answers
1kviews
C++ code reading from a text file, storing value in int, and outputting properly rounded float
Late important updates (unified) I found, that on my Pi's Debian 12 Bookworm (arm64), there is just an older g++-12 available. ...
4votes
2answers
959views
LeetCode 3366: Minimum Array Sum - w/o DP/memoisation
This program tried to solve LeetCode problem 3366: Minimum Array Sum. It fails for k odd, op1+op2 high enough such there are more odd value to optionally subtract k from than subtractions to allot. A ...
10votes
2answers
2kviews
Robust error handling mechanism in C++ (safer than std::expected)
I've been looking into and experimenting with various paradigms for error handling in C++. My goals for a robust error handling mechanism would be: Enforce handling the error cases (in other words, ...
6votes
1answer
121views
Using `std::variant` to multiplex input methods
I have known about std::variant for a while but had dismissed it as not very useful (I have revised that opinion now). But I would like a second opinion on my usage ...
4votes
1answer
86views
Result class to get either value or error
Recently, I had written a Result class. Basically I wanted a function to return result value on success and some error code on failure. ...
6votes
1answer
217views
Implementing a python range like function in C++17
I came up with a C++17 (I cannot use C++ >= 20 in my project) implementation of a python-like range function (class). The Code "range.hpp" ...
3votes
1answer
72views
Implementation of an Ordered Character Class #2
Overview This is a follow-up review request incorporating commented from the following prior review: Implementation of an Ordered Character Class. I have incorporated many of the suggestions made by ...
2votes
2answers
92views
Implementation of an Ordered Character Class
Overview The code below is my attempt a solving a problem that came up in one of my projects. I needed a type that could be constrained to a defined list of characters, be set to a specific character, ...
2votes
1answer
81views
Calculating array segment uniformity using a segment tree
You have to analyze some array of \$n\$ numbers. In particular, you are interested in the so-called array uniformity. Suppose that in the array the number \$b_1\$ appears \$k_1\$ times, \$b_2\$ \$k_2\$...
2votes
2answers
104views
Minimum length of specific substrings
Given the string \$s\$. It is required to answer n queries. The \$i\$th query consists of an integer \$k_i\$ and a string \$m_i\$, the answer is the minimum length of the string \$t\$ such that \$t\$ ...
6votes
3answers
212views
Find the number of cycles of length 3
Given the count. Find the number of cycles of length 3. Input format: The first line contains two integers n and m (1 < n, m ≤ 3✕10⁵) — the number of vertices and edges, respectively. Each of the ...